$package('YiYa.company');
YiYa.company = function(){
	var _box = null;
	var _this = {
		config:{
			event:{
				edit:function(){
					var selected = _box.utils.getCheckedRows();
					var record = selected[0];
					if(record.city!=null){
						var url = '../district/loadDistrictList.do?parentCode='+record.city.code;
						$('#cc2').combobox('reload', url);
					}
					_box.handler.edit();
				}
			},
			dataGrid:{
				title:'单位列表',
				url:'dataList_by_serCompany.do',
				columns:[[
				          {field:'id',checkbox:true},
				          {field:'name',title:'单位名称',width:150},
				          {field:'linkman',title:'联系人',width:80},
				          {field:'phoneNumber',title:'单位电话',width:100},
				          {field:'mobileNumber',title:'手机号码',width:100},
				          {field:'city_code',title:'市',width:120,
				        	  formatter:function(value,row,index){
				        		  return new Object(row["city"]).name;
						  }},
						  {field:'county_code',title:'县(县级市、区)',width:120,
				        	  formatter:function(value,row,index){
				        		  return new Object(row["county"]).name;
						  }},
				          {field:'address',title:'地址',width:120,
							  formatter:function(value,row,index){
								  if(value!=undefined){
									  if(value.length>10){
										  var str = value.substring(0,8);
										  return str.concat('......');	  
									  }
									  return value;
								  }
								  
						  }},
						  {field:'ser_company_id',title:'挂钩维护公司',width:150,
				        	  formatter:function(value,row,index){
				        		  return new Object(row["serCompany"]).name;
						  }},
				          {field:'state',title:'状态',width:60,
				        	  formatter:function(value,row,index){
				        		  var result = '';
				        		  if(row.state==0||row.state==null){
				        			  result = '已过期';
				        		  }else if(row.state==1){
				        			  result = '正常';
				        		  }
				        		  return result;
						  }},
				          {field:'expiry_date',title:'到期日期',width:120,sortable:true,
				        	  formatter:function(value,row,index){
				        		  if(row["expiryDate"]!=null){
				        		  return new Date(row["expiryDate"].split(" ")[0].replace(/-/g,'/')).format("yyyy-MM-dd");
				        		  }
						      }
						  }
				          ]],
	          rowStyler: function(index,row){
	              if (row.state==0||row.state==null){
	            	  return 'color: #F00';
	              }
              },
	          toolbar:[
	                   {id:'btnadd',text:'添加',btnType:'add'},
	                   {id:'btnedit',text:'编辑',btnType:'edit'},
	                   {id:'btndelete',text:'删除',btnType:'remove'},
	                   {id:'btnview',text:'查看',btnType:'view'}
	                   ]
			}
		},
		init:function(){
			$('#cc1').combobox({
			    onChange:function(newValue,oldValue){
			    	$("#cc2").combobox('clear');
			    }
			});
			_box = new YDataGrid(_this.config);
			_box.init();
		}
	}
	return _this;
}();

$(function(){
	YiYa.company.init();
});


